﻿using System;

namespace Ajax.Common
{
    /// <summary>
    /// 数学公式
    /// </summary>
    public class MyMath
    {

        #region 进一法
        /// <summary>
        /// 两数相除得数用进一法
        /// </summary>
        /// <param name="TotalNo">有N行数据</param>
        /// <param name="PageSize">每页显示N行</param>
        /// <returns>分页后有X页</returns>
        public static int GetCeiling(double TotalNo, double PageSize)
        {
            return (int)System.Math.Ceiling(TotalNo / PageSize);
        }
        #endregion

        #region 去尾法
        /// <summary>
        /// 去尾法
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        static public int GetInteger(double d)
        {
            string str = d.ToString().Split('.')[0];
            return int.Parse(str);
        }

        
        #endregion

        /// <summary>
        /// 返回百分比
        /// </summary>
        /// <param name="FenZhi">分子</param>
        /// <param name="FenMu">分母</param>
        /// <returns></returns>
        public static string Percent(int FenZhi, int FenMu)
        {
            decimal d = Convert.ToDecimal(FenZhi) / Convert.ToDecimal(FenMu);

            return Math.Round(d * 100, 4) + " ％";
        }
    }
}